package com.jian.mygame;

import android.util.Log;

public class MyUtil extends Object{
	
	//Return value: -PI...+PI
	static public float calculateAngle( float x, float y){
		float angle = 0.0f;

		//Calculate angle based on the current position
		/*
		if( x > 0 ) {
			angle = (float) (Math.atan((y)/(x)));
		} else {
			angle = (float) (Math.atan((y)/(x))+Math.PI);
		}
		*/
		Log.d("MyUtil", "calculateAngle() x: " + x + " /y: " + y);
		//angle = (float)Math.atan2(x, y);
		//description of Math.atan2 is wrong
		angle = (float)Math.atan2(y, x);
		Log.d("MyUtil", "calculateAngle() angle: " + angle);
		
		return angle;
	}
	
	//Return value: 0...+2PI
	static public float changeAngleRange( float angle ) {
		if( angle >= Math.PI*2 ) {
			angle = (float)(angle%(Math.PI*2));
		} else if( angle < 0 ) {
			do {
				angle += Math.PI*2;
			} while( angle < 0 );
		}
		
		return angle;
	}
	
	
	static public float angleToDegree( float angle ) {
		float degree = (float)(angle * 180/Math.PI);
		
		return degree;
	}
}
